package com.ruoyi.active.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.active.domain.LotteryPrize;
import com.ruoyi.active.service.ILotteryPrizeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 抽奖奖品Controller
 * 
 * @author ruoyi
 * @date 2025-08-01
 */
@RestController
@RequestMapping("/prize")
public class LotteryPrizeController extends BaseController
{
    @Autowired
    private ILotteryPrizeService lotteryPrizeService;

    /**
     * 查询抽奖奖品列表
     */
    @RequiresPermissions("active:prize:list")
    @GetMapping("/list")
    public TableDataInfo list(LotteryPrize lotteryPrize)
    {
        startPage();
        List<LotteryPrize> list = lotteryPrizeService.selectLotteryPrizeList(lotteryPrize);
        return getDataTable(list);
    }

    /**
     * 导出抽奖奖品列表
     */
    @RequiresPermissions("active:prize:export")
    @Log(title = "抽奖奖品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LotteryPrize lotteryPrize)
    {
        List<LotteryPrize> list = lotteryPrizeService.selectLotteryPrizeList(lotteryPrize);
        ExcelUtil<LotteryPrize> util = new ExcelUtil<LotteryPrize>(LotteryPrize.class);
        util.exportExcel(response, list, "抽奖奖品数据");
    }

    /**
     * 获取抽奖奖品详细信息
     */
    @RequiresPermissions("active:prize:query")
    @GetMapping(value = "/{prizeId}")
    public AjaxResult getInfo(@PathVariable("prizeId") Long prizeId)
    {
        return success(lotteryPrizeService.selectLotteryPrizeByPrizeId(prizeId));
    }

    /**
     * 新增抽奖奖品
     */
    @RequiresPermissions("active:prize:add")
    @Log(title = "抽奖奖品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LotteryPrize lotteryPrize)
    {
        return toAjax(lotteryPrizeService.insertLotteryPrize(lotteryPrize));
    }

    /**
     * 修改抽奖奖品
     */
    @RequiresPermissions("active:prize:edit")
    @Log(title = "抽奖奖品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LotteryPrize lotteryPrize)
    {
        return toAjax(lotteryPrizeService.updateLotteryPrize(lotteryPrize));
    }

    /**
     * 删除抽奖奖品
     */
    @RequiresPermissions("active:prize:remove")
    @Log(title = "抽奖奖品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{prizeIds}")
    public AjaxResult remove(@PathVariable Long[] prizeIds)
    {
        return toAjax(lotteryPrizeService.deleteLotteryPrizeByPrizeIds(prizeIds));
    }
}
